import * as auth from '@/utils/auth';
import { obj2FormData } from '@/utils/index.js';

const BackUrl = 'backUrl';

export default {
	install(Vue) {

		//获取alioss配置
		Vue.prototype.alioss = function () {

			return {
				region: 'oss-cn-beijing',
				accessKeyId: 'LTAI4FddafeDip56D3unXw4X',
				accessKeySecret: 'bJMwAQCPQJAIA5JDVOKA6KpGzVDMyQ',
				bucket: 'fcschool',
				secure:true
			}
		}

		//获取token
		Vue.prototype.getUserInfo = auth.getUserInfo;

		Vue.prototype.obj2FormData = obj2FormData ;

		//延迟执行,time单位为毫秒
        Vue.prototype.later = function (callback, time = 1500) {
            setTimeout(callback, time);
        };

        Vue.prototype.apiBack = function(res, callback = null){
            const { status, info, data } = res ;
            if(status == 0) {
                //如果需要延时                
                callback(data);
            }
		}
		
		Vue.prototype.addFunction = async function({url, params, callback=undefined, message}){
			const { code } =await Vue.prototype.$axios.post(url,params);
			message = message || '新增成功' ;
			if(code==0){
				Vue.prototype.$toast.success(message);
				if(callback){					
					callback();
				}else{
					Vue.prototype.later(()=>{
						this.$router.go(-1);
					})
				}
			}
		}
	}
}
